package com.pj.wisdomlogistics.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.entity.QuLeaderInfo;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by HelloWorld on 2017/9/8.
 */

public class QuLeaderAdapter extends BaseAdapter<QuLeaderInfo, BaseViewHolder> {

    public QuLeaderAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent , R.layout.item_rv_leader);
    }

    @Override
    public void bindCustomViewHolder(final BaseViewHolder viewHolder, final int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final QuLeaderInfo item = getItem(position);


        viewHolder.getTextView(R.id.tv_name).setText(item.getName());
        //viewHolder.getTextView(R.id.tv_phone).setText(item.getMobile() + "");
//
//        viewHolder.getView(R.id.ll_layout).setTag(0);
//
//        viewHolder.getView(R.id.ll_layout).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if((int)v.getTag() == 0){
//                    viewHolder.getImageView(R.id.iv_icon).setBackgroundResource(R.drawable.people_blue);
//                    v.setBackgroundResource(R.drawable.select);
//                    v.setTag(1);
//                    mListener.itemClick(item.getId() , item.getName());
//                }else if((int)v.getTag() == 1){
//                    viewHolder.getImageView(R.id.iv_icon).setBackgroundResource(R.drawable.people_white);
//                    v.setBackgroundResource(R.drawable.portion_bg_normal);
//                    v.setTag(0);
//                    mListener.itemClick(item.getId() , item.getName());
//                }
//            }
//        });


        LinearLayout layout = viewHolder.getView(R.id.ll_layout);

        if(item.isSelected()){
            layout.setBackgroundResource(R.drawable.select);
            viewHolder.getImageView(R.id.iv_icon).setImageResource(R.drawable.people_blue);
        }

        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(item.isSelected()) return;
                mListener.itemClick(position , item.getId() , item.getName());
            }
        });
    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public listener mListener;

    public interface listener {
        public void itemClick(int pisition , String id , String name);
    }

    public void setListener(listener mListener) {
        this.mListener = mListener;
    }
}
